/*
 * testTraitement.c
 *
 *  Created on: 26 déc. 2011
 *      Author: lmartel
 */

// FICHIER pour STOCKER les tests des fonctions de traitement.c
// ------------ A INSERER DANS MAIN ---------------

//---------------------------------------------------------------------------------------------
//                                      LOAD
//---------------------------------------------------------------------------------------------

// ----------------- LOAD REG <- IMM --------------
//      Exemple : R3 = 4
/* * /
    unsigned regDest = 3;
    unsigned source = 20;
    printf("Source : %d\nDestination : %d\n", source, regDest);
    printf("\nLOAD REG <- IMM  AVANT\n");
    afficherRegistres();
    loadRegImm(source, regDest);
    printf("\nLOAD REG <- IMM  APRES\n");
    afficherRegistres();
    /* */

// ----------------- LOAD REG <- DIR --------------
//      Exemple : R3 = [4]
/* * /
    unsigned regDest = 3;
    unsigned memDest = 3;
    unsigned source = -1;
    storeDirImm(source, memDest);
    printf("Source : %d\nDestination : %d\n", source, regDest);
    printf("\nLOAD REG <- DIR  AVANT\n");
    afficherRegistres();
    afficherMemoire();
    loadRegDir(memDest, regDest);
    printf("\nLOAD REG <- DIR  APRES\n");
    afficherRegistres();
    afficherMemoire();
    /* */

// ----------------- LOAD REG <- IND --------------
//      Exemple : R3 = [R4]
/* * /
    unsigned regDest = 3;
    unsigned regMem = 2;
    unsigned memDest = 3;
    loadRegImm(regDest, regMem);

    unsigned source = 6;
    storeDirImm(source, memDest);
    printf("Source : %d\nDestination : %d\n", source, regDest);
    printf("\nLOAD REG <- IND  AVANT\n");
    afficherRegistres();
    afficherMemoire();
    loadRegInd(regMem, regDest);
    printf("\nLOAD REG <- IND  APRES\n");
    afficherRegistres();
    afficherMemoire();
    /* */

//---------------------------------------------------------------------------------------------
//                                      STORE
//---------------------------------------------------------------------------------------------

// ----------------- STORE DIR <- IMM --------------
//      Exemple : [4] = 20
/* * /
    unsigned memDest = 4;
    unsigned source = 20;
    printf("Source : %d\nDestination : [%d]\n", source, memDest);
    printf("\nSTORE DIR <- IMM  AVANT\n");
    afficherRegistres();
    afficherMemoire();
    storeDirImm(source, memDest);
    printf("\nSTORE DIR <- IMM  APRES\n");
    afficherRegistres();
    afficherMemoire();
    /* */

// ----------------- STORE DIR <- REG --------------
//      Exemple : [4] = R6
/* * /
    unsigned memDest = 4;
    unsigned regDest = 6;
    unsigned source = 20;
    loadRegImm(source, regDest);
    printf("Source : %d\nDestination : [%d]\n", source, memDest);
    printf("\nSTORE DIR <- REG  AVANT\n");
    afficherRegistres();
    afficherMemoire();
    storeDirReg(regDest, memDest);
    printf("\nSTORE DIR <- REG  APRES\n");
    afficherRegistres();
    afficherMemoire();
    /* */

// ----------------- STORE IND <- IMM --------------
//      Exemple : [R5] = #3
/* * /
    unsigned memDest = 4;
    unsigned source = 20;
    unsigned numReg = 3;
    loadRegImm (memDest, numReg); // R3 = 4
    printf("Source : %d\nDestination : [%d]\n", source, memDest);
    printf("\nSTORE IND <- IMM  AVANT\n");
    afficherRegistres();
    afficherMemoire();
    storeIndImm(source, numReg);
    printf("\nSTORE IND <- IMM  APRES\n");
    afficherRegistres();
    afficherMemoire();
    /* */


// ----------------- STORE IND <- REG --------------
//      Exemple : [R5] = R6
/* * /
    unsigned memDest = 4;
    unsigned source = 20;
    unsigned regSource = 7;
    unsigned numReg = 3;
    loadRegImm (memDest, numReg); // R3 = 4
    loadRegImm (source, regSource); // R7 = 20
    printf("Source : %d\nDestination : [%d]\n", source, memDest);
    printf("\nSTORE IND <- REG  AVANT\n");
    afficherRegistres();
    afficherMemoire();
    storeIndReg(regSource, numReg);
    printf("\nSTORE IND <- REG  APRES\n");
    afficherRegistres();
    afficherMemoire();
    /* */


//---------------------------------------------------------------------------------------------
//                                      ADD
//---------------------------------------------------------------------------------------------

// ----------------- ADD REG <- REG + REG --------------
//      Exemple : R3 = R3 + R4
/* * /
    unsigned regA = 3;
    unsigned regB = 6;
    unsigned sourceA = 4;
    unsigned sourceB = 7;
    loadRegImm(sourceA, regA);
    loadRegImm(sourceB, regB);
    printf("\nADD REG <- REG + REG  AVANT\n");
    afficherRegistres();
    addRegReg(regB, regA);
    printf("\nADD REG <- REG + REG  APRES\n");
    afficherRegistres();
    /* */

// ----------------- ADD REG <- REG + IMM --------------
//      Exemple : R3 = R3 + 6
/* * /
    unsigned regA = 3;
    unsigned sourceA = 4;
    unsigned sourceImm = 19;
    loadRegImm(sourceA, regA);
    printf("\nADD REG <- REG + IMM  AVANT\n");
    afficherRegistres();
    addRegImm(sourceImm, regA);
    printf("\nADD REG <- REG + IMM  APRES\n");
    afficherRegistres();
    /* */


// ----------------- ADD REG <- REG + DIR --------------
//      Exemple : R3 = R3 + [4]
/* * /
    unsigned regA = 3;
    unsigned memB = 2;
    unsigned sourceA = 4;
    unsigned sourceB = 18;
    storeDirImm(sourceB, memB);
    loadRegImm(sourceA, regA);
    printf("\nADD REG <- REG + DIR  AVANT\n");
    afficherRegistres();
    afficherMemoire();
    addRegDir(memB, regA);
    printf("\nADD REG <- REG + DIR  APRES\n");
    afficherRegistres();
    afficherMemoire();
    /* */


// ----------------- ADD REG <- REG + IND --------------
//      Exemple : R3 = R3 + [R4]
/* * /
    unsigned regA = 3;
    unsigned memB = 2;
    unsigned regB = 7;
    unsigned sourceA = 4;
    unsigned sourceB = 18;
    loadRegImm(memB, regB);
    storeDirImm(sourceB, memB);
    loadRegImm(sourceA, regA);
    printf("\nADD REG <- REG + IND  AVANT\n");
    afficherRegistres();
    afficherMemoire();
    addRegInd(regB, regA);
    printf("\nADD REG <- REG + IND  APRES\n");
    afficherRegistres();
    afficherMemoire();
    /* */

//---------------------------------------------------------------------------------------------
//                                      SUB
//---------------------------------------------------------------------------------------------


// ----------------- SUB REG <- REG + REG --------------
//      Exemple : R3 = R3 - R4
/* * /
    unsigned regA = 3;
    unsigned regB = 6;
    unsigned sourceA = 5;
    unsigned sourceB = 4;
    loadRegImm(sourceA, regA);
    loadRegImm(sourceB, regB);
    printf("\nSUB REG <- REG + REG  AVANT\n");
    afficherRegistres();
    subRegReg(regB, regA);
    printf("\nSUB REG <- REG + REG  APRES\n");
    afficherRegistres();
    /* */


// ----------------- SUB REG <- REG + IMM --------------
//      Exemple : R3 = R3 - 6
/* * /
    unsigned regA = 3;
    unsigned sourceA = 24;
    unsigned sourceImm = 19;
    loadRegImm(sourceA, regA);
    printf("\nSUB REG <- REG + IMM  AVANT\n");
    afficherRegistres();
    subRegImm(sourceImm, regA);
    printf("\nSUB REG <- REG + IMM  APRES\n");
    afficherRegistres();
    /* */

// ----------------- SUB REG <- REG + DIR --------------
//      Exemple : R3 = R3 - [4]
/* * /
    unsigned regA = 3;
    unsigned memB = 2;
    unsigned sourceA = 24;
    unsigned sourceB = 18;
    storeDirImm(sourceB, memB);
    loadRegImm(sourceA, regA);
    printf("\nSUB REG <- REG + DIR  AVANT\n");
    afficherRegistres();
    afficherMemoire();
    subRegDir(memB, regA);
    printf("\nSUB REG <- REG + DIR  APRES\n");
    afficherRegistres();
    afficherMemoire();
    /* */


// ----------------- SUB REG <- REG + IND --------------
//      Exemple : R3 = R3 - [R4]
/* * /
    unsigned regA = 3;
    unsigned memB = 2;
    unsigned regB = 7;
    unsigned sourceA = 34;
    unsigned sourceB = 18;
    loadRegImm(memB, regB);
    storeDirImm(sourceB, memB);
    loadRegImm(sourceA, regA);
    printf("\nSUB REG <- REG + IND  AVANT\n");
    afficherRegistres();
    afficherMemoire();
    subRegInd(regB, regA);
    printf("\nSUB REG <- REG + IND  APRES\n");
    afficherRegistres();
    afficherMemoire();
    /* */


//---------------------------------------------------------------------------------------------
//                                      JMP
//---------------------------------------------------------------------------------------------


// ----------------- JMP IMM --------------
//      Exemple : JMP #3
/* * /
    unsigned jmpSource = 3;
    printf("\nJMP IMM  AVANT\n");
    afficherRegistres();
    jmpImm(jmpSource);
    printf("\nJMP IMM  APRES\n");
    afficherRegistres();
    /* */


//---------------------------------------------------------------------------------------------
//                                      JEQ
//---------------------------------------------------------------------------------------------


// ----------------- JEQ IMM --------------
//      Exemple : JEQ #3
/* * /
    unsigned source = 3;
    printf("\nJEQ IMM  AVANT\n");
    afficherRegistres();
    jeqImm(source);
    printf("\nJEQ IMM  APRES    avec SR = 0 \n");
    afficherRegistres();
    source = 8;
    reg.sr = 7;
    jeqImm(source);
    printf("\nJEQ IMM  APRES    avec SR = 0 \n");
    afficherRegistres();
    /* */

//---------------------------------------------------------------------------------------------
//                                      TEST DE PROGRAMMES
//---------------------------------------------------------------------------------------------

// ----------------- TEST LOAD --------------
/* * /
    mot programme [] = {
            {.codage = {LOAD, REGIMM, 0, 3}},   // R3 = 5
            {.brut =  5 },
            {.codage = {LOAD, REGDIR, 0, 7}},   // R7 =  [1] = 5
            {.brut =  1 },
            {.codage = {LOAD, REGIMM, 0, 6}},   // R6 = 4
            {.brut =  4 },
            {.codage = {LOAD, REGIND, 7, 4}},   // R4 = [R7]
    };
    /* */

// ----------------- TEST STORE --------------
    /* * /
    mot programme [] = {
            {.codage = {LOAD, REGIMM, 0, 3}},   // R3 = 5
            {.brut =  17 },
            {.codage = {STORE, DIRREG, 3, 0}},   // [19] = R3
            {.brut =  19 },
            {.codage = {STORE, DIRIMM, 0, 0}},   // [18] = 19
            {.brut =  19 }, // Immediat
            {.brut =  18 },  // Direct
            {.codage = {STORE, INDIMM, 0, 3}},   // [R3] = 90
            {.brut =  90 },
            {.codage = {LOAD, REGIMM, 0, 6}},   // R6 = 5
            {.brut =  16 },
            {.codage = {STORE, INDREG, 3, 6}},   // [R3] = R3
    };
    /* */


// ----------------- TEST ADD --------------
    /* * /
    mot programme [] = {
            {.codage = {LOAD, REGIMM, 0, 3}},   // R3 = 20
            {.brut =  20 },
            {.codage = {LOAD, REGIMM, 0, 6}},   // R6 = 10
            {.brut =  10 },
            {.codage = {ADD, REGREG, 3, 6}},    // R6 = R6 + R3 = 30
            {.codage = {ADD, REGIMM, 0, 6}},     // R6 = R6 + 5 = 35
            {.brut =  5 },
            {.codage = {ADD, REGDIR, 0, 6}},     // R6 = R6 + [1] = 55
            {.brut =  1 },
            {.codage = {LOAD, REGIMM, 0, 2}},   // R2 = 1
            {.brut =  1 },
            {.codage = {ADD, REGIND, 2, 6}},    // R6 = R6 + [R2] = 75
    };

    /* */


// ----------------- TEST SUB --------------
    /* * /
    mot programme [] = {
            {.codage = {LOAD, REGIMM, 0, 3}},   // R3 = 20
            {.brut =  20 },
            {.codage = {LOAD, REGIMM, 0, 6}},   // R6 = 90
            {.brut =  90 },
            {.codage = {SUB, REGREG, 3, 6}},    // R6 = R6 - R3 = 70
            {.codage = {SUB, REGIMM, 0, 6}},     // R6 = R6 - 5 = 65
            {.brut =  5 },
            {.codage = {SUB, REGDIR, 0, 6}},     // R6 = R6 - [1] = 45
            {.brut =  1 },
            {.codage = {LOAD, REGIMM, 0, 2}},   // R2 = 1
            {.brut =  1 },
            {.codage = {SUB, REGIND, 2, 6}},    // R6 = R6 + [R2] = 25
    };
    /* */


// ----------------- TEST JMP --------------
    /* * /
    mot programme [] = {
            {.codage = {LOAD, REGIMM, 0, 3}},   // R3 = 20
            {.brut =  20 },
            {.codage = {JMP, REGIMM, 0, 6}},   // JMP 20
            {.brut =  20 },
            {.codage = {SUB, REGREG, 3, 6}},    // R6 = R6 - R3 = 70
            {.codage = {SUB, REGIMM, 0, 6}},     // R6 = R6 - 5 = 65
            {.brut =  5 },
    };
    /* */


// ----------------- TEST CALL --------------
    /* * /
    mot programme [] = {
            {.codage = {LOAD, REGIMM, 0, 3}},   // R3 = 20
            {.brut =  20 },
            {.codage = {CALL, REGIMM, 0, 6}},   // CALL 7
            {.brut =  7 },
            {.codage = {SUB, REGREG, 3, 6}},    // R6 = R6 - R3 = 70
            {.codage = {SUB, REGIMM, 0, 6}},     // R6 = R6 - 5 = 65
            {.brut =  5 },
            {.codage = {CALL, DIRIMM, 0, 6}},     // CALL 12
            {.brut =  12 },
            {.codage = {LOAD, REGIMM, 0, 2}},   // R2 = 1
            {.brut =  1 },
            {.codage = {SUB, REGIND, 2, 6}},    // R6 = R6 + [R2] = 25
    };
    /* */


// ----------------- TEST PUSH --------------
    /* * /
    mot programme [] = {
            {.codage = {LOAD, REGIMM, 0, 3}},   // R3 = 57
            {.brut =  57 },
            {.codage = {LOAD, REGIMM, 0, 6}},   // R6 = 90
            {.brut =  90 },
            {.codage = {PUSH, INDREG, 3, 6}},    // PUSH R3
            {.codage = {PUSH, REGREG, 3, 6}},    // PUSH R3
            {.codage = {PUSH, DIRREG, 6, 6}},    // PUSH R6
            {.codage = {PUSH, REGIMM, 0, 6}},    // PUSH #120
            {.brut =  120 },
            {.codage = {PUSH, DIRIMM, 0, 6}},    // PUSH #121
            {.brut =  121 },
            {.codage = {PUSH, INDIMM, 0, 6}},    // PUSH #122
            {.brut =  122 },
            {.codage = {PUSH, REGDIR, 0, 6}},    // PUSH [59]
            {.brut =  59 },
            {.codage = {PUSH, REGIND, 3, 0}},    // PUSH [R3]
    };
    /* */


// ----------------- TEST POP --------------
    /* * /
    mot programme [] = {
            {.codage = {LOAD, REGIMM, 0, 3}},   // R3 = 57
            {.brut =  57 },
            {.codage = {PUSH, INDREG, 3, 6}},    // PUSH R3
            {.codage = {PUSH, REGREG, 3, 6}},    // PUSH R3
            {.codage = {PUSH, DIRREG, 3, 6}},    // PUSH R3
            {.codage = {PUSH, DIRREG, 3, 6}},    // PUSH R3
            {.codage = {POP, REGDIR, 6, 0}},    // POP R0
            {.codage = {POP, REGIND, 6, 1}},    // POP R1
            {.codage = {POP, REGREG, 6, 2}},    // POP R2
            {.codage = {POP, REGIMM, 6, 4}},    // POP R4

            {.codage = {LOAD, REGIMM, 0, 3}},   // R3 = 57
            {.brut =  60 },
            {.codage = {PUSH, INDREG, 3, 6}},    // PUSH R3
            {.codage = {PUSH, REGREG, 3, 6}},    // PUSH R3
            {.codage = {PUSH, DIRREG, 3, 6}},    // PUSH R3
            {.codage = {PUSH, DIRREG, 3, 6}},    // PUSH R3
            {.codage = {POP, DIRREG, 0, 3}},   // POP [22]
            {.brut =  32 },
            {.codage = {POP, DIRIMM, 0, 3}},   // POP[23]
            {.brut =  33 },
            {.codage = {LOAD, REGIMM, 0, 6}},   // R3 = 57
            {.brut =  40 },
            {.codage = {LOAD, REGIMM, 0, 7}},   // R3 = 57
            {.brut =  41 },
            {.codage = {POP, INDREG, 6, 6}},    // PUSH R3
            {.codage = {POP, INDIMM, 3, 7}},    // PUSH R3

    };
    /* */


// ----------------- TEST RET --------------
    /* * /
    mot programme [] = {
            {.codage = {LOAD, REGIMM, 0, 3}},   // R3 = 57
            {.brut =  5 },
            {.codage = {PUSH, REGREG, 3, 6}},    // PUSH R3
            {.codage = {RET, INDREG, 3, 6}},    // PUSH R3
            {.codage = {PUSH, DIRREG, 3, 6}},    // PUSH R3
            {.codage = {PUSH, REGIMM, 3, 6}},    // PUSH R3
            {.brut =  50 },
            {.codage = {HALT, }},    // HALT
    };
    /* */
